﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GiaSu.DataAccess.DataContext;
using GiaSu.DataAccess.Entity;
using GiaSu.DataAccess.Repository;

namespace GiaSu.Bussiness.Common
{
    public class EntityBusiness<T> : IEntityBusiness<T> where T : Base
    {
        private IGenericRepository<T> genericRepository;
        private IUnitOfWork unitOfWork;
        public EntityBusiness(IGenericRepository<T> genericRepository, IUnitOfWork unitOfWork)
        {
            this.genericRepository = genericRepository;
            this.unitOfWork = unitOfWork;
        }
        public IList<T> GetAll()
        {
            return genericRepository.GetAll().ToList();
        }

        public void Add(T entity)
        {
            this.genericRepository.Add(entity);
            this.genericRepository.SaveChanges();
           // this.unitOfWork.Commit();
        }

        public void Delete(T entity)
        {
            this.genericRepository.Delete(entity);
            this.unitOfWork.Commit();
        }

        public void Edit(T entity)
        {
            this.genericRepository.Edit(entity);
            this.unitOfWork.Commit();
        }
    }
}
